function z = my_Obj(v)
cd('C:\Users\amir\Desktop\optimization_codes')
load('objmat');
if(isempty(S.vessels))
    b=mexcpp(v,S.time,S.needle_num,S.xr);
else
    b=mexcpp(v,S.time,S.needle_num,S.xr,S.row_vessel-1,S.col_vessel-1,S.I3_vessel-1);
end
%   tic
%   q=find(b(:,:,:)<=S.temp);
%   [row col I3] = ind2sub(size(b), q);
%   in = sum(inhull([row+min(S.X1),col+min(S.X2), I3+min(S.X3)],[S.x,S.y,S.z],S.face));
%   [volume,area] = triangulationVolume(S.face,S.x,S.y,S.z);
%   z=3*(volume/10-in)+size(row,1)-in;
%   toc
BW=b<S.temp;
in=0;
for i=1:size(S.row,1)
    B=sum(BW(S.row(i,1)+S.boundx,S.col(i,1)+S.boundy,S.I3(i,1)+S.boundz));
    in=in+B;
end
A=sum(sum(sum(BW)));
out=A-in;
z=S.w(1)*(size(S.row,1)-in)+S.w(2)*out;
S.count=S.count+1;
save('objmat','S')
% q=find(b(:,:,:)<=S.temp);
% [row col I3] = ind2sub(size(b), q);
% scatter3(row+min(S.x)-S.boundx,col+min(S.y)-S.boundy, I3+min(S.z)-S.boundz,'filled')
% hold on
% scatter3(S.row+min(S.x),S.col+min(S.y), S.I3+min(S.z),'filled')
% hold off
% exportOBJ( 'C:\Users\amir\Desktop\optimization_codes\iceball.obj', [row+min(S.x)-S.boundx col+min(S.y)-S.boundy I3+min(S.z)-S.boundz], []);
% exportOBJ( 'C:\Users\amir\Desktop\optimization_codes\test_tumor.obj', [S.row+min(S.x) S.col+min(S.y)  S.I3+min(S.z)], []);

end
